/*
 * @Descripttion:
 * @version: 1.0.1
 * @Author: daipeng
 * @Date: 2020-08-12 16:56:37
 * @LastEditors: daipeng
 * @LastEditTime: 2020-11-30 11:39:56
 */
const mainfun = {
  //禁止滚动条滚动
  unScroll() {
    // 方法一
    var top = $(document).scrollTop();
    $(document).on("scroll.unable", function (e) {
      $(document).scrollTop(top);
    });
    // 方法二
    // document.body.style.position = 'fixed';
    // document.body.style.overflow = 'hidden';
  },
  //移除禁止
  removeUnScroll() {
    // 方法一
    $(document).unbind("scroll.unable");
    // 方法二
    // document.body.style.position = 'relative';
    // document.body.style.overflow = 'auto';
  },
  scrollTop() {
    $("html,body").animate(
      {
        scrollTop: 0,
      },
      0
    ); //回到顶端
  },
  //转换年月日方法
  getDate(format, str) {
    let oDate = new Date(str);
    let oYear = oDate.getFullYear();
    let oMonth = oDate.getMonth() + 1;
    let oDay = oDate.getDate();
    // let h = oDate.getHours();
    // let mm = oDate.getMinutes();
    // let s = oDate.getSeconds();
    if (format == "yyyy-mm-dd") {
      var oTime = oYear + "-" + this.getzf(oMonth) + "-" + this.getzf(oDay); //最后拼接时间
    } else if (format == "yyyy/mm/dd") {
      var oTime = oYear + "/" + this.getzf(oMonth) + "/" + this.getzf(oDay); //最后拼接时间
    }
    return oTime;
  },
  //补0操作
  getzf(num) {
    if (parseInt(num) < 10) {
      num = "0" + num;
    }
    return num;
  },
  //保留两位小数
  filterNumber(val) {
    let obj = Number(val).toFixed(2);
    return obj;
  },
  // 转换百分比
  percentage(point) {
    console.log(point);
    if (point == undefined || point == "") {
      str = "-";
    } else {
      var str = Number(point * 100).toFixed(1);
      str += "%";
    }
    return str;
  },
  // 默认时间设置
  setdate(e) {
    var oneMs = 24 * 3600 * 1000;
    var newdate = new Date();
    newdate.setDate(newdate.getDate());
    var alltimestamp = newdate.getTime() + e * oneMs;
    var timestamp = new Date(alltimestamp);
    var year = timestamp.getFullYear();
    var day = timestamp.getDate();
    var month = timestamp.getMonth() + 1;
    if (month < 10) {
      month = "0" + month;
    }
    if (day < 10) {
      day = "0" + day;
    }

    return year + "-" + month + "-" + day;
  },
};
export { mainfun };



// WEBPACK FOOTER //
// ./src/assets/js/main.js